package sk.stuba.fiit.pki.ws.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

import sk.stuba.fiit.pki.service.PkiService;
import sk.stuba.fiit.pki.ws.schema.beans.OcspRequest;
import sk.stuba.fiit.pki.ws.schema.beans.OcspResponse;
import sk.stuba.fiit.pki.ws.service.MarshalingOCSPService;

@Endpoint
public class OCSPEndpoint implements MarshalingOCSPService {

	@Autowired
	PkiService pkiService;
	
	@PayloadRoot(localPart=OCSP_REQUEST, namespace=NAMESPACE)
	public OcspResponse getOcspResponse(OcspRequest request) {
		try {
			String issuer = request.getOcspreq().getIssuer();
			String serialNum = request.getOcspreq().getSerialNumber();
			OcspResponse response =  pkiService.getOCSPInfo(issuer,serialNum);
			return response;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new OcspResponse();
	}

}
